﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using System.IO;
using System.Data.SqlClient;
namespace syc.Produce.Report
{
    public partial class 产品销售价格收入月报 : System.Web.UI.Page
    {
        protected HSSFWorkbook hssfworkbook;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.DList_month.SelectedIndex = DateTime.Today.Month - 1;
                this.DList_year.Text = DateTime.Today.Year.ToString();

            }
            Button_Query_Click(null, null);
        }
        protected void WriteToFile()
        {
            DateTime d;

            d = DateTime.Today;

            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + d.ToShortDateString() + ".xls\"");
            hssfworkbook.Write(Response.OutputStream);
        }

        protected void InitializeWorkbook()
        {

            FileStream file = new FileStream(HttpContext.Current.Server.MapPath("/Produce/模板/产品销售价格收入月报表.xls"), FileMode.Open, FileAccess.Read);

            hssfworkbook = new HSSFWorkbook(file);

            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "陕西延长石油材料有限公司";
            hssfworkbook.DocumentSummaryInformation = dsi;

            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
            si.Subject = "报表";
            si.Title = "产品销售价格收入月报表";
            hssfworkbook.SummaryInformation = si;
        }
        protected void Button_Save_Click(object sender, EventArgs e)
        {

            InitializeWorkbook();
            HSSFSheet sheet1 = hssfworkbook.GetSheet("产品销售价格收入月报表");
            Button_Query_Click(null, null);
            sheet1.GetRow(1).GetCell(4).SetCellValue(DateTime.Today.Year + "年" + DateTime.Today.Month + "月");
            //sheet1.GetRow(17).GetCell(4).SetCellValue(DateTime.Today.Year+"年"+DateTime.Today.Month+"月");
           
          

            //sheet1.GetRow(25).GetCell(8).SetCellValue("报出日期："+DateTime.Today.Year+"-"+DateTime.Today.Month+"-"+DateTime.Today.Day);
            //sheet1.ForceFormulaRecalculation = true;
            WriteToFile();
            Response.End();
        }

        protected void Button_Query_Click(object sender, EventArgs e)
        {

        }
        protected void DList_year_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void DList_month_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}
